package cn.smartaccount.demo.common.util;

import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;

import java.util.Arrays;
import java.util.List;

/**
 * @author xuluquan
 * @date 2020-05-08 11:58
 */
public class EnvironmentUtil {

    /**
     * 获取数据
     *
     * @param key
     * @return boolean
     * @author xuluquan
     * @date 2019-08-23 15:55
     */
    public static String getProperty(String key) {
        ApplicationContext context = SpringContextUtil.getApplicationContext();
        if (context == null) {
            return StringUtils.EMPTY;
        }
        return context.getEnvironment().getProperty(key);
    }

    /**
     * 获取系统管理员角色
     *
     * @param
     * @return 系统管理员角色
     * @author xuluquan
     * @date 2020-05-08 12:04
     */
    public static List<String> getSystemAdminList() {
        String adminRoleUuid = getProperty("admin.default.role");
        if (StringUtils.isBlank(adminRoleUuid)) {
            return Lists.newArrayList();
        }
        return Arrays.asList(adminRoleUuid.split(",|;"));
    }


}
